package com.itheima.recursion_single;

/**
 * 递归求和 n + n - 1, ... + 1
 *
 * @FileName E06Sum
 * @Description
 * @Author Sword
 * @date 2025-03-13
 **/
public class E06Sum {

    public static long sum(long n) {
        return f(n);
    }

    //f(n) = f(n - 1) + n
    private static long f(long n) {
        if (n == 1) {
            return 1;
        }
        return n + f(n - 1);
    }

    public static void main(String[] args) {
        long sum = E06Sum.sum(100);
        System.out.println(sum);
    }
}
